package com.baidu.controller;

import com.baidu.model.entity.AlbumModel;
import com.baidu.service.impl.AlbumControllerServiceImpl;
import com.until.pagination.PaginationRequest;
import com.until.response.RestfulCode;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * @author user
 */
@RestController
@RequestMapping("album")
public class AlbumController {

    @Autowired
    private AlbumControllerServiceImpl userControllerService;

    @PostMapping(value = "",produces = "application/json;charset=UTF-8")
    public RestfulCode.CodeSatCode addAlbum(@RequestBody Map<String,Object> request){
        AlbumModel albumModel = new AlbumModel(
                request.get("name").toString(),
                Integer.valueOf(request.get("userid").toString()),
                Integer.valueOf(request.get("limits").toString())
        );
        return userControllerService.instepAlbumModel(albumModel);
    }

    @GetMapping("user/{userid}")
    public RestfulCode.CodeSatCode findAll(@ModelAttribute PaginationRequest page, @PathVariable String userid){
        return userControllerService.selectByUserId(Integer.valueOf(userid),page);
    }
    
}
